package com.scs.application.modules.upgrade.menu;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.scs.application.modules.sys.service.MenuService;
import com.scs.application.modules.upgrade.db.entity.MenuForUpgrade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

@Service
public class UpgradeMenuService {


    @Autowired
    @Lazy
    private MenuService menuService;

    public void upgrade() throws Exception {
        try {
        } catch (Exception e) {
            throw e;
        }
    }
    private void parseMenuJsonArrayString(String jsonString) throws Exception {
        JSONArray jaMenu = JSONObject.parseArray(jsonString);
        for (int i = 0; i < jaMenu.size(); i++) {
            parseMenuJsonString(jaMenu.get(i).toString());
        }
    }
    private void parseMenuJsonString(String jsonString) throws Exception {
        JSON json = (JSON) JSONObject.parse(jsonString);
        MenuForUpgrade menu = json.toJavaObject(MenuForUpgrade.class);
        menuService.save(menu);

        String children = menu.getChildren();
        if (children != null && children != "") {
            parseMenuJsonArrayString(children);
        }
    }
}
